clear all
cap close
set more off

cd ".\Data_Program"

* ==============================================================================
*  Table 6: Col 2, 3, 5: SCI based network measure
* ==============================================================================

use beforereg_sci_iv,clear

    * McDash refi share
merge 1:1 quarter county using mcdash4merge
drop if _merge==2  
drop _merge 

xtset county quarter
gen newrefi_sr_100 = newrefi_sr/100

global control2 hpgr popgr empgr fracyyy* fracbyy* subprime baboveyy* dfinad linflow loutflow hpgr2 popgr2 empgr2 fracy2 fracb2 subprime2 babove2yy* dfinad2 


* Col 2: change specification
reghdfe dfinshare dfinshare2 $control2 [aw=w],a(county division#quarter) cluster(county) resid(residual_chg)
reghdfe newrefi_sr_100 residual_chg dfinshare2 $control2 [aw=w],a(county division#quarter) cluster(county)

* Col 3: change IV specification
ivreghdfe newrefi_sr_100 residual_chg (dfinshare2=dfinshare2_outcz) $control2 [aw=w], a(division#quarter county) cluster(county) 

* Col 5: level specification
reghdfe finshare finshare2 $control2 [aw=w],a(county division#quarter) cluster(county) resid(residual_lv)
reghdfe newrefi_sr_100 l.residual_lv l.finshare2 $control2 [aw=w],a(county division#quarter) cluster(county)


* ==============================================================================
*  Table 6: Col 1, 4: Distance based network measure
* ==============================================================================

use beforereg_distance,clear

    * McDash refi share
merge 1:1 quarter county using mcdash4merge
drop if _merge==2  
drop _merge 

xtset county quarter
gen newrefi_sr_100 = newrefi_sr/100

global control2 hpgr popgr empgr fracyyy* fracbyy* subprime baboveyy* dfinad hpgr2 popgr2 empgr2 fracy2 fracb2 subprime2 babove2yy* dfinad2 linflow loutflow


* Col 1: change 
reghdfe dfinshare dfinshare2 $control2 [aw=w],a(county division#quarter) cluster(county) resid(residual_chg)
reghdfe newrefi_sr_100 residual_chg dfinshare2 $control2 [aw=w],a(county division#quarter) cluster(county)

* Col 4: level specification
reghdfe finshare finshare2 $control2 [aw=w],a(county division#quarter) cluster(county) resid(residual_lv)
reghdfe newrefi_sr_100 l.residual_lv l.finshare2 $control2 [aw=w],a(county division#quarter) cluster(county)

